package at.fhj.mobsecdev.cookit.util;

import java.io.File;

import android.content.res.Resources;
import at.fhj.mobsecdev.cookit.R;
import at.fhj.mobsecdev.cookit.model.Recipe;

/**
 * Validates recipe for missing values etc.
 */
public class RecipeValidator {
	
	/**
	 * Validates recipe 
	 * @param r recipe to validate
	 * @param errorString reasons for errors in recipe object
	 * @param res resources object
	 * @return true, if recipe is valid
	 */
	public boolean validate(Recipe r, StringBuilder errorString, Resources res)
	{
		if(r.getName() == null || r.getName().trim().equals(""))
		{
			errorString.append(res.getString(R.string.error_name_empty));
			return false;
		}
		
		if(r.getCookingInstruction() == null || r.getCookingInstruction().trim().equals(""))
		{
			errorString.append(res.getString(R.string.error_preparation_empty));
			return false;
		}
		
		if(r.getIngredients() == null || r.getIngredients().size() == 0)
		{
			errorString.append(res.getString(R.string.error_no_ingredient));
			return false;
		}
		
		if(r.getImageFilePath() == null || !new File(r.getImageFilePath()).exists())
		{
			errorString.append(res.getString(R.string.error_no_image));
			return false;
		}
		
		return true;
	}
}
